import LoadingComponent from '@/components/loading';

const Loading = {};
Loading.installed = false;
Loading.install = Vue => {
  const LoadingConstructor = Vue.extend(LoadingComponent);
  const tpl = new LoadingConstructor();
  tpl.$mount();

  Vue.prototype.$loading = {};
  Vue.prototype.$loading.show = text => {
    if (Loading.installed) {
      tpl.$data.text = text;
      return;
    }
    document.body.appendChild(tpl.$el);
    Loading.installed = true;
  };
  Vue.prototype.$loading.hide = () => {
    document.body.removeChild(tpl.$el);
    Loading.installed = false;
  };
};
export default Loading;
